package com.eat.mapper;

import com.github.pagehelper.Page;
import com.eat.dto.GoodsSalesDTO;
import com.eat.dto.OrdersPageQueryDTO;
import com.eat.entity.Orders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 下订单
     * @param order
     */
    void insert(Orders order);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id}")
    Orders getOrder(Long id);

    /**
     * 取消订单
     * @param id
     */
    @Delete("delete from orders where id = #{id}")
    void delete(Long id);

    /**
     * 查询历史订单
     * @param status
     * @return
     */
    Page<Orders> page(Integer status);

    /**
     * 处理超时订单
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> setTimeOutAndOrder(Integer status, LocalDateTime orderTime);

    /**
     * 分页查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> getPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 各个状态的订单数量统计
     * @param status
     * @return
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer getStatistics(Integer status);

    /**
     * 统计日期营业额
     * @param map
     * @return
     */
    @Select("select sum(amount) from orders where order_time between #{begin} and #{end} and status = #{status}")
    Double sumByMap(Map map);

    /**
     * 根据动态查询订单数
     * @param map
     * @return
     */
    Integer getOrdersStatistics(Map map);

    /**
     * 动态获取时间区间内的销量Top10
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);

    /**
     * 动态获取订单数据
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
